# Calculating expectations and p-values for the binomial tests


################
### TABLE 1##### 
################

#The same tests are also reported in Appendix Tables 1-2-3 with case details.

# Accel/Decel TOLERATION 5-year (make up 43 of 80 years in 1939-2018; 43 of 74 years in 1945-2018; 27 of 50 years in 1969-2018; 21 of 43 years in 1976-2018)

# row 1 column 1
pbinom(40.9, 54, 43/80, lower.tail=FALSE)
43/80 * 54

# row 1 column 2
pbinom(16, 25, 43/80, lower.tail=TRUE)
43/80 * 25

# row 1 column 3
pbinom(40.9, 46, 43/74, lower.tail=FALSE)
43/74 * 46

# row 1 column 4
pbinom(16, 25, 43/74, lower.tail=TRUE)
43/74 * 25

# row 1 column 5
pbinom(18.9, 24, 27/50, lower.tail=FALSE)
27/50 * 24

# row 1 column 6
pbinom(12, 19, 27/50, lower.tail=TRUE)
27/50 * 19

# row 1 column 7
pbinom(7.9, 13, 21/43, lower.tail=FALSE)
21/43 * 13

# row 1 column 8
pbinom(9, 15, 21/43, lower.tail=TRUE)
21/43 * 15


# Accel/Decel ATTACK 5-year (make up 42 of 80 years in 1939-2018; 39 of 74 years in 1945-2018; 33 of 50 years in 1969-2018; 33 of 43 years in 1976-2018)

# Row 2 Column 1
pbinom(16, 54, 42/80, lower.tail=TRUE)
42/80 * 54

# Row 2 Column 2
pbinom(11.9, 25, 42/80, lower.tail=FALSE)
42/80 * 25

# Row 2 Column 3
pbinom(14, 46, 39/74, lower.tail=TRUE)
39/74 * 46

# Row 2 Column 4
pbinom(11.9, 25, 39/74, lower.tail=FALSE)
39/74 * 25

# Row 2 Column 5
pbinom(7, 24, 33/50, lower.tail=TRUE)
33/50 * 24

# Row 2 Column 6
pbinom(11.9, 19, 33/50, lower.tail=FALSE)
33/50 * 19

# Row 2 Column 7
pbinom(7, 13, 33/43, lower.tail=TRUE)
33/43 * 13

# Row 2 Column 8
pbinom(11.9, 15, 33/43, lower.tail=FALSE)
33/43 * 15


# Accel/Decel DEAL 5-year (make up 31 of 80 years in 1939-2018; 31 of 74 years in 1945-2018; 31 of 50 years in 1969-2018; 25 of 43 years in 1976-2018)

# Row 3 Column 1
pbinom(16.9, 54, 31/80, lower.tail=FALSE)
31/80 * 54

# Row 3 Column 2
pbinom(6, 25, 31/80, lower.tail=TRUE)
31/80 * 25

# Row 3 Column 3
pbinom(16.9, 46, 31/74, lower.tail=FALSE)
31/74 * 46

# Row 3 Column 4
pbinom(6, 25, 31/74, lower.tail=TRUE)
31/74 * 25

# Row 3 Column 5
pbinom(16.9, 24, 31/50, lower.tail=FALSE)
31/50 * 24

# Row 3 Column 6
pbinom(6, 19, 31/50, lower.tail=TRUE)
31/50 * 19

# Row 3 Column 7
pbinom(8.9, 13, 25/43, lower.tail=FALSE)
25/43 * 13

# Row 3 Column 8
pbinom(3, 15, 25/43, lower.tail=TRUE)
25/43 * 15



##############################
### APPENDIX TABLE 4 ######### 
##############################


# Accel/Decel TOLERATION 3-year (make up 38 of 80 years in 1939-2018; 38 of 74 years in 1945-2018, 18 of 50 years in 1969-2018; 14 of 43 years in 1976-2018)

pbinom(30.9, 54, 38/80, lower.tail=FALSE)
38/80 * 54

pbinom(13, 25, 38/80, lower.tail=TRUE)
38/80 * 25

pbinom(30.9, 46, 38/74, lower.tail=FALSE)
38/74 * 46

pbinom(13, 25, 38/74, lower.tail=TRUE)
38/74 * 25

pbinom(11.9, 24, 18/50, lower.tail=FALSE)
18/50 * 24

pbinom(9, 19, 18/50, lower.tail=TRUE)
18/50 * 19

pbinom(2.9, 13, 14/43, lower.tail=FALSE)
14/43 * 13

pbinom(7, 15, 14/43, lower.tail=TRUE)
14/43 * 15



##############################
### APPENDIX TABLE 5 ######### 
##############################

# Accel/Decel ATTACK 3-year (make up 36 of 80 years in 1939-2018; 33 of 74 years in 1945-2018, 27 of 50 years in 1969-2018; 29 of 43 years in 1976-2018)

pbinom(13, 54, 36/80, lower.tail=TRUE)
36/80 * 54

pbinom(11.9, 25, 36/80, lower.tail=FALSE)
36/80 * 25

pbinom(11, 46, 33/74, lower.tail=TRUE)
33/74 * 46

pbinom(11.9, 25, 33/74, lower.tail=FALSE)
33/74 * 25

pbinom(6, 24, 27/50, lower.tail=TRUE)
27/50 * 24

pbinom(11.9, 19, 27/50, lower.tail=FALSE)
27/50 * 19

pbinom(6, 13, 29/43, lower.tail=TRUE)
29/43 * 13

pbinom(11.9, 15, 29/43, lower.tail=FALSE)
29/43 * 15


##############################
### APPENDIX TABLE 6 ######### 
##############################

# Accel/Decel DEAL 3-year (make up 23 of 80 years in 1939-2018; 23 of 74 years in 1945-2018; 23 of 50 years in 1969-2018; 19 of 43 years in 1976-2018)

pbinom(13.9, 54, 23/80, lower.tail=FALSE)
23/80 * 54

pbinom(5, 25, 23/80, lower.tail=TRUE)
23/80 * 25

pbinom(13.9, 46, 23/74, lower.tail=FALSE)
23/74 * 46

pbinom(5, 25, 23/74, lower.tail=TRUE)
23/74 * 25

pbinom(13.9, 24, 23/50, lower.tail=FALSE)
23/50 * 24

pbinom(5, 19, 23/50, lower.tail=TRUE)
23/50 * 19

pbinom(8.9, 13, 19/43, lower.tail=FALSE)
19/43 * 13

pbinom(3, 15, 19/43, lower.tail=TRUE)
19/43 * 15









